package com.unicom.priceboard.data;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.unicom.priceboard.data.vo.SecurityElement;

public class OpenPriceParser extends BaseXMLParser{
	//for storing Node Value
	private StringBuffer tempVal;
		
	//to maintain context
	private SecurityElement tempStock;

	public static HashMap<String, SecurityElement> mapOpenPrice = new HashMap<String,SecurityElement>();
	

	public void parseDocument(String xmlFile) {
		super.parseDocument(xmlFile);				
	}
	
	public void parseDocument(InputStream is) throws IOException{
		super.parseDocument(is);
	}


	//Event Handlers
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		//reset
		tempVal = new StringBuffer("");
		if(qName.equalsIgnoreCase("STOCK")) {
			tempStock = new SecurityElement();
		}		
	}
	

	public void characters(char[] ch, int start, int length) throws SAXException {
//		tempVal = new String(ch,start,length);
		tempVal.append(ch,start,length);
	}
	
	public void endElement(String uri, String localName, String qName) throws SAXException {

		if(qName.equalsIgnoreCase("STOCK")) {
			mapOpenPrice.put(tempStock.getSymbolCode(),tempStock); 
			
		} else if (qName.equalsIgnoreCase("Symbol_code")) {
			tempStock.setSymbolCode(tempVal.toString());
		} else if (qName.equalsIgnoreCase("openprice")){
			tempStock.setOpenPrice(Integer.valueOf(tempVal.toString()));
		} else if (qName.equalsIgnoreCase("Ceil")){
			tempStock.setCeiling(Integer.valueOf(tempVal.toString()));
		} else if (qName.equalsIgnoreCase("Floor")){
			tempStock.setFloor(Integer.valueOf(tempVal.toString()));
		}else if (qName.equalsIgnoreCase("Refprice")){
			tempStock.setPriorClosePrice(Integer.valueOf(tempVal.toString()));
		}

			
	}

	@Override
	public void endDocument() throws SAXException {
		
	}


}